import request from "@/utils/request";
import {OrderPageResult, OrderQuery, OrderRefundVo} from "@/api/order/types";
import {AxiosPromise} from "axios";

const baseUri = "/mv1/api/order";

/**
 * 获取角色分页数据
 *
 * @param queryParams
 */
export function getOrderList(
  queryParams?: OrderQuery
): AxiosPromise<OrderPageResult> {
  return request({
    url: baseUri + "/",
    method: "get",
    params: queryParams,
  });
}


/**
 * 订单打印任务
 * @param query
 */
export function getOrderPrinterTasks(queryParams: OrderQuery) {
  return request({
    url: baseUri + "/printer/task",
    method: "get",
    params: queryParams,
  });
}

/**
 * 打印统计数据
 * @param queryParams
 */
export function statPrinterData(queryParams: any) {
  return request({
    url: baseUri + "/printer_stat",
    method: "get",
    params: queryParams,
  });
}


/**
 * 订单筛选条件
 * @param queryParams
 */
export function getOrderInitFilter(queryParams?: any) {
  return request({
    url: baseUri + "/init_filter",
    method: "get",
    params: queryParams,
  });
}

/**
 * 打印
 * @param data
 */
export function printerOrder(data: any) {
  return request({
    url: baseUri + "/printer",
    method: "post",
    params: data,
  });
}

/**
 * 确认接单
 * @param data
 */
export function acceptDeliver(data: any) {
  return request({
    url: baseUri + "/accept",
    method: "post",
    params: data,
  });
}

/**
 * 订单状态统计
 * @param query
 */
export function statusStatList(data: OrderQuery) {
  return request({
    url: baseUri + "/stat_status",
    method: "get",
    params: data
  });
}


/**
 * 订单详情
 * @param id
 */
export function orderDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
    // params: data || {}
  });
}

/**
 * 退款
 * @param id
 */
export function refundOrder(id: number | string, data: OrderRefundVo) {
  // data['type'] = type;
  return request({
    url: baseUri + "/refund/" + id,
    method: "post",
    params: data
  });
}

/**
 * 备注
 * @param id
 */
export function editNote(id: number | string, note: string) {
  return request({
    url: baseUri + "/edit_note/" + id,
    method: "put",
    params: {
      note: note
    }
  });
}

/**
 * 删除订单
 *
 * @param ids
 */
export function deleteOrder(ids: string | number) {
  return request({
    url: baseUri + "/" + ids,
    method: "delete",
  });
}

/**
 * 导出用户
 *
 * @param queryParams
 * @returns
 */
export function exportShopOrder(queryParams: OrderQuery) {
  return request({
    url: baseUri + "/export",
    method: "get",
    params: queryParams,
    responseType: "arraybuffer",
  });
}

